package com.new_blog.mapper;

import com.new_blog.model.Articleinfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.new_blog.model.vo.ArticleInfoVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author TQ02
 * @since 2024-03-21
 */
@Mapper
public interface ArticleinfoMapper extends BaseMapper<Articleinfo> {

    //分页
    @Select("select * from articleinfo order by aId desc limit #{pasize} offset #{ofset}")
    List<ArticleInfoVo> getAllPage(@Param("pasize")Integer pasize, @Param("ofset")Integer ofset);

    //文章总数
    @Select ("select count(*) from articleinfo")
    Integer getCount();

    //指定文章
    @Select("select * from articleinfo where aId=#{aId}")
    Articleinfo getId(Integer aid);


    //获取指定人的文章
    @Select("select count(*) from articleinfo where uId=#{uId}")
    Integer getCountId(String uId);

    //获取指定人的文章的种类
    @Select("SELECT COUNT(DISTINCT type) FROM articleinfo where uId=#{uId}")
    Integer getCountType(String uId);

    //获取指定人的文章总数
    @Delete("DELETE from articleinfo where aId=#{aid}")
    Integer delete(@Param("aid") int num);

    @Select("select * from articleinfo where content like concat('%', #{text}, '%') order by aId desc limit #{pasize} offset #{ofset}")
    List<ArticleInfoVo> getSearchPage(@Param("pasize")Integer pasize, @Param("ofset")int offest,@Param("text") String text);

    @Select("select count(*) from articleinfo where content like concat('%', #{text}, '%')")
    int getSearchCount(@Param("text")String text);
}
